local hx__quandao = fk.CreateSkill{
  name = "hx__quandao",
}

local spec = {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(hx__quandao.name) and (data.card.type == Card.TypeBasic or data.card.type ~= Card.TypeBasic)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if not player:isKongcheng() then
      local basic = table.filter(player:getCardIds("h"), function(id)
        return Fk:getCardById(id).type == Card.TypeBasic
      end)
      local unbasic = table.filter(player:getCardIds("h"), function(id)
        return Fk:getCardById(id).type ~= Card.TypeBasic
      end)
      if #basic ~= #unbasic then
        local n = #basic - #unbasic
        if n > 0 then
          room:askToDiscard(player, {
            min_num = n,
            max_num = n,
            include_equip = false,
            skill_name = hx__quandao.name,
            cancelable = false,
            pattern = tostring(Exppattern{ id = basic }),
          })
        else
          room:askToDiscard(player, {
            min_num = -n,
            max_num = -n,
            include_equip = false,
            skill_name = hx__quandao.name,
            cancelable = false,
            pattern = tostring(Exppattern{ id = unbasic }),
          })
        end
      end
    end
    if not player.dead then
      player:drawCards(2, hx__quandao.name)
    end
  end,
}

hx__quandao:addEffect(fk.CardUsing, spec)
hx__quandao:addEffect(fk.CardResponding, spec)


return hx__quandao
